package com.example.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.example.entity.SysUser;
import com.example.mapper.SysUserMapper;
import com.example.service.ISysUserService;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统用户 服务实现类
 * </p>
 *
 * @author lilufeng
 * @since 2016-11-28
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

	@Autowired
	private SysUserMapper sysUserMapper;

	@Cacheable(value = "sysUsers",key = "'sys111'")
	@Override
	public List<String> queryAllPerms(Long userId) {
		return sysUserMapper.queryAllPerms(userId);
	}

	@Override
	public boolean add(SysUser sysUser) {
		String password = new SimpleHash("md5", sysUser.getPassword(), ByteSource.Util.bytes(sysUser.getUsername()), 2).toHex();
		sysUser.setPassword(password);
		return sysUserMapper.insert(sysUser) == 1 ? true : false;
	}

}
